package com.skp.shaphan.connect;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import com.skp.job.ProjectJobException;
import com.skp.shaphan.savedConnections.SavedConnection;

public class SQLServer extends BasicConnect {

	public SQLServer(SavedConnection conn) {
		super(conn);
	}

	@Override
	public Connection connect(Properties props) {
		//Properties props = super.getConnectionDescription().getProperties();
		Connection connection = null;
				
		String url = "jdbc:sqlserver://" + props.getProperty("serverName") + ":" + props.getProperty("portNumber");
		try {
			connection = DriverManager.getConnection(url, props.getProperty("userName"), props.getProperty("password"));
			String dbName = props.getProperty("databaseName");
			if(dbName != null && dbName.trim().length() > 0) {
				connection.setCatalog(dbName);
			}
		} catch (SQLException e) {
			(new ProjectJobException(e)).displayException();
			return null;
		}
		
		return connection;
	}
}
